<?php

include ("global.php");

$pagetitle=" - Topic admin";

$links=" > Topic admin";

include ("header.php");

$forumconfigarray=allforumconfigarray($forum);
$moderatorsarray=explode(",",$forumconfigarray[1]);

if($userloggedinarray[15]!=="administrator"&&(!in_array($useridarray[$navboardlogin],$moderatorsarray)||$userloggedinarray[0]=="")){
   $tplcontent['notice']="Must be logged in as administrator or moderator to perform action '$action'<br>
   Please check that you are logged in and that you have correct access";
   echo template('notice',$tplcontent);
}else{

$topicnum=$topic;
$topictime=topic_numtotime($forum,$topicnum);

$forumconfigarray=getdata("$configarray[2]/$forum.php");
$moderatorsarray=explode("\t",$forumconfigarray[1]);

if($action=="closetopic"){
  writedata("$configarray[2]/$forum/$topictime.php","closed",0);

  $tplcontent['notice']="Forum '$forum', Topic '$topicnum' closed<br>
  Auto redirecting <a href=\"index.php?forum=$forum&topic=$topicnum&page=0\">back to topic</a>";
  echo template('notice',$tplcontent);
  
  echo "<meta http-equiv=\"refresh\" content=\"1; url=index.php?forum=$forum&topic=$topicnum&page=0\">";
}

if($action=="opentopic"){
  writedata("$configarray[2]/$forum/$topictime.php","open",0);

  $tplcontent['notice']="Forum '$forum', Topic '$topicnum' opened<br>
  Auto redirecting <a href=\"index.php?forum=$forum&topic=$topicnum&page=0\">back to topic</a>";
  echo template('notice',$tplcontent);
  
  echo "<meta http-equiv=\"refresh\" content=\"1; url=index.php?forum=$forum&topic=$topicnum&page=0\">";
}

if($action=="movetopic"){

 if(!$moveforum){
 unset($tplcontent);
 	
 $tplcontent['formheader'].="<form action=\"admin_topicoptions.php\" method=post>";
 $tplcontent['formheader'].="<input type=hidden name=\"forum\" value=\"$forum\" size=40>";
 $tplcontent['formheader'].="<input type=hidden name=\"topic\" value=\"$topicnum\" size=40>";
 $tplcontent['formheader'].="<input type=hidden name=\"action\" value=\"$action\" size=40>";
 $tplcontent['topicnum'].=$topicnum;

 $tplcontent['forumsmenu'].="<select size=1 name=\"moveforum\" class=\"forminput\">";

 $tplcontent['forumsmenu'].=forumsmenu("0",0);

 $tplcontent['forumsmenu'].="</select>";
 
 $tplcontent['submitbutton'].="<input type=submit name=\"submit\" value=\"Move\" class=\"formbutton\">";
 $tplcontent['formfooter'].="</form>";

 echo template('admintopicoptionsmove',$tplcontent);
 }

 if($moveforum){
  $topicidarray=getdata("$configarray[2]/${moveforum}_topics.php");
  $newtopicid=count($topicidarray);
  
  $postarray=listfiles("$configarray[2]/$forum/$topictime");

  createdir("$configarray[2]/$moveforum/$topictime");

  for($n=0;$n<count($postarray);$n++){
   @rename("$configarray[2]/$forum/$topictime/$postarray[$n].php","$configarray[2]/$moveforum/$topictime/$postarray[$n].php");
  }

  @rename("$configarray[2]/$forum/$topictime.php","$configarray[2]/$moveforum/$topictime.php");

  @rmdir("$configarray[2]/$forum/$topictime");
  
  writedata("$configarray[2]/${moveforum}_topics.php",$topictime,$newtopicid);
  writedata("$configarray[2]/${moveforum}/$topictime.php",$newtopicid,3);

  unset($tplcontent);
  $tplcontent['notice']="Auto redirecting <a href=\"index.php?forum=$moveforum&topic=$newtopicid&page=0\">back to topic</a>
  <meta http-equiv=\"refresh\" content=\"0; url=index.php?forum=$moveforum&topic=$newtopicid&page=0\">";
  echo template('notice',$tplcontent);

 }

}

}

include("footer.php");

?>
